package cloud.tianai.mate.captcha.generator.impl;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class Demo3 {

    public static void main(String[] args) {
        int width = 600; // 图像宽度
        int height = 360; // 图像高度
        int mosaicSizeX = 64; // 马赛克块大小
        int mosaicSizeY = 32; // 马赛克块大小

        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
//        g.setColor(new Color(255, 255, 255));
//        g.fillRect(0, 0, width, height);

        for (int x = 0; x < width; x += mosaicSizeX) {
            for (int y = 0; y < height; y += mosaicSizeY) {
                Color randomColor = getRandomColor();
                g.setColor(randomColor);
                g.fillRect(x, y, mosaicSizeX, mosaicSizeY);
            }
        }

        System.out.println(111);
    }

    private static Color getRandomColor() {
        List<Color> list = Arrays.asList(
                new Color(254, 220, 172),
                new Color(218, 196, 220),
                new Color(252, 249, 207),
                new Color(181, 203, 225),
                new Color(251, 182, 180),
                new Color(227, 209, 184)
        );
        return list.get((int) (Math.random() * list.size()));
    }

}
